package com.yjq.programmer.controller.admin;

import com.yjq.programmer.dto.PageDTO;
import com.yjq.programmer.dto.ResponseDTO;
import com.yjq.programmer.dto.UserDTO;
import com.yjq.programmer.service.IUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 杨杨吖
 * @QQ 823208782
 * @WX yjqi12345678
 * @create 2022-09-12 8:59
 */
@RestController("AdminUserController")
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    private IUserService userService;

    /**
     * 分页获取用户数据
     * @param pageDTO
     * @return
     */
    @PostMapping("/list")
    public ResponseDTO<PageDTO<UserDTO>> getUserListByPage(@RequestBody PageDTO<UserDTO> pageDTO){
        return userService.getUserListByPage(pageDTO);
    }

    /**
     * 保存用户数据(添加、修改)
     * @param userDTO
     * @return
     */
    @PostMapping("/save")
    public ResponseDTO<Boolean> saveUser(@RequestBody UserDTO userDTO){
        return userService.saveUser(userDTO);
    }

    /**
     * 删除用户数据
     * @param userDTO
     * @return
     */
    @PostMapping("/remove")
    public ResponseDTO<Boolean> removeUser(@RequestBody UserDTO userDTO){
        return userService.removeUser(userDTO);
    }


    /**
     * 用户登录操作处理
     * @param userDTO
     * @return
     */
    @PostMapping("/login")
    public ResponseDTO<UserDTO> adminLogin(@RequestBody UserDTO userDTO){
        return userService.adminLogin(userDTO);
    }

    /**
     * 获取当前登录用户
     * @param userDTO
     * @return
     */
    @PostMapping("/getLoginUser")
    public ResponseDTO<UserDTO> getLoginUser(@RequestBody UserDTO userDTO){
        return userService.getLoginUser(userDTO);
    }


    /**
     * 用户退出登录
     * @return
     */
    @PostMapping("/logout")
    public ResponseDTO<Boolean> logout(@RequestBody UserDTO userDTO){
        return userService.logout(userDTO);
    }

    /**
     * 获取用户总数
     * @return
     */
    @PostMapping("/total")
    public ResponseDTO<Integer> getUserTotal(){
        return userService.getUserTotal();
    }

    /**
     * 获取所有用户数据
     * @return
     */
    @PostMapping("/all")
    public ResponseDTO<List<UserDTO>> getAllUser(){
        return userService.getAllUser();
    }


}
